package com.zzb.framework.role.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zzb.framework.role.dao.SysRoleUserDAO;
import com.zzb.framework.role.entity.IUser;
import com.zzb.framework.role.entity.SysRoleUser;

import com.zzb.framework.common.BaseResponse;
import com.zzb.framework.common.BaseService;
import com.zzb.framework.common.ServiceException;
import com.zzb.framework.validator.annotation.ValidatorEnabled;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* 用户角色关系表 service类
*/
@Service
public class SysRoleUserService extends BaseService<SysRoleUserDAO,SysRoleUser> {
    private static final Logger logger = LoggerFactory.getLogger(SysRoleUserService.class);
    @Autowired
    private SysRoleUserDAO sysRoleUserDAO;
    @Override
    public SysRoleUserDAO getDAO() {
        return sysRoleUserDAO;
    }
    /**删除用户角色关系表*/
    public BaseResponse deleteRoleUser(String id,IUser operate) throws ServiceException{
        //TODO  ZZB 20170222
        return deleteById(id);
    }
    /**保存用户角色关系表*/
    @ValidatorEnabled
    public BaseResponse<SysRoleUser> saveRoleUser(SysRoleUser sysRoleUser, IUser operator) throws ServiceException{
        logger.info("正在保存用户角色关系表["+ JSON.toJSONString(sysRoleUser)+"]["+JSON.toJSONString(operator)+"]");
        //TODO  ZZB 20170222
        return insertOrUpdate(sysRoleUser,operator);
    }
    @Transactional
    public void deleteByUserId(String userId){
        getDAO().getMapper().delete(new EntityWrapper<SysRoleUser>().eq("user_id",userId));
    }

    @Transactional
    public void deleteByRoleId(String roleId){
        getDAO().getMapper().delete(new EntityWrapper<SysRoleUser>().eq("role_id",roleId));
    }
}
